package com.teen9g.infoplatformserver.controller;

import com.github.pagehelper.PageInfo;
import com.teen9g.PageQueryDTO.CanteenShopPageQueryDTO;
import com.teen9g.PageQueryDTO.CanteenShopUserPageQueryDTO;
import com.teen9g.dto.CanteenShopDTO;
import com.teen9g.entity.CanteenShop;
import com.teen9g.infoplatformserver.service.CanteenShopService;
import com.teen9g.result.Result;
import com.teen9g.userVO.CanteenShopUserVO;
import com.teen9g.vo.CanteenShopVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/canteenshop")
public class CanteenShopController {

    @Autowired
    private CanteenShopService canteenShopService;

    /**
     * 选择页面-分页查询
     *
     * @param PageQueryDTO 查询条件
     * @return 分页数据
     */
    @GetMapping("/page")
    public Result<PageInfo<CanteenShopVO>> pageQuery(CanteenShopPageQueryDTO PageQueryDTO) {
        log.info("食堂商铺分页查询");
        PageInfo<CanteenShopVO> result = canteenShopService.pageQuery(PageQueryDTO);
        return Result.success(result);
    }

    /**
     * 个人信息页面-分页查询
     *
     * @param PageQueryDTO 查询条件
     * @return 分页数据
     */
    @GetMapping("/page/user")
    public Result<PageInfo<CanteenShopUserVO>>
    pageQueryByUserId(CanteenShopUserPageQueryDTO PageQueryDTO) {
        log.info("个人信息页面食堂商铺分页查询:{}", PageQueryDTO);
        PageInfo<CanteenShopUserVO> result = canteenShopService.pageQueryByUserId(PageQueryDTO);
        return Result.success(result);
    }

    /**
     * 添加食堂商铺
     *
     * @param canteenShopDTO 食堂商铺
     * @return 添加结果
     *
     */
    @PostMapping("/add")
    public Result<Integer> add(@RequestBody CanteenShopDTO canteenShopDTO) {
        log.info("添加食堂商铺");
        int add = canteenShopService.add(canteenShopDTO);
        return Result.success(add);
    }

    /**
     * 修改食堂商铺
     *
     * @param canteenShopDTO 食堂商铺
     * @param id             食堂商铺id
     * @return 修改结果
     */
    @PutMapping("/update/{id}")
    public Result<Integer> update
    (@RequestBody CanteenShopDTO canteenShopDTO, @PathVariable("id") Integer id) {
        log.info("修改食堂商铺");
        int update = canteenShopService.update(canteenShopDTO, id);
        return Result.success(update);
    }

    /**
     * 删除食堂商铺
     *
     * @param id 食堂商铺id
     * @return 删除结果
     */
    @DeleteMapping("/delete/{id}")
    public Result<Integer> delete(@PathVariable("id") Integer id) {
        log.info("删除食堂商铺");
        int delete = canteenShopService.delete(id);
        return Result.success(delete);
    }

    /**
     * 初步展示页获取所有食堂店铺
     *
     * @return 所有食堂店铺
     */
    @GetMapping("/getAllFront")
    public Result<List<CanteenShopVO>> getAllFront() {
        log.info("初步展示页获取所有食堂商铺");
        List<CanteenShopVO> list = canteenShopService.getAllFront();
        return Result.success(list);
    }

    /**
     * 根据id获取食堂商铺
     *
     * @param shopId 食堂商铺id
     * @return 食堂商铺
     */
    @GetMapping("/get/single/{shopId}")
    public Result<CanteenShop> get(@PathVariable Integer shopId) {
        log.info("根据id获取食堂商铺");
        CanteenShop canteenShop = canteenShopService.getById(shopId);
        return Result.success(canteenShop);
    }

    /**
     * 增加店铺浏览量
     *
     * @param shopId 店铺id
     * @return 增加结果
     */ 
    @PostMapping("/addView/{shopId}")
    public Result<String> addView(@PathVariable Integer shopId) {
        log.info("增加店铺浏览量");
        canteenShopService.addView(shopId);
        return Result.success();
    }

    /**
     * 初步展示页获取所有一食堂商铺 （停用）
     *
     * @return 所有一食堂商铺
     */
    @GetMapping("/get/1")
    public Result<List<CanteenShopVO>> getFirstAllFront() {
        log.info("初步展示页获取所有一食堂商铺");
        List<CanteenShopVO> list = canteenShopService.getFirstAllFront();
        return Result.success(list);
    }

    /**
     * 初步展示页获取所有二食堂商铺（停用）
     *
     * @return 所有二食堂商铺
     */
    @GetMapping("/get/2")
    public Result<List<CanteenShopVO>> getSecondAllFront() {
        log.info("初步展示页获取所有二食堂商铺");
        List<CanteenShopVO> list = canteenShopService.getSecondAllFront();
        return Result.success(list);
    }
}
